# -*- coding:utf-8 -*-

__author__ = 'dong'

import requests
import time
from gevent.pool import Pool
from gevent import monkey

monkey.patch_all()

NUM = 0


def download_images(url):
    r = requests.get(url)
    print r.headers
    global NUM
    NUM += 1
    filename = 'images/%s.bmp' % str(NUM)
    with open(filename, 'wb') as fd:
        fd.write(r.content)


if __name__ == '__main__':
    urls = [
        'http://www.555gk.com/include/getcode.asp?t={0}'.format(int(time.time()))] * 100
    pool = Pool(20)
    pool.map(download_images, urls)
